﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Globalization;
using Ch.Admin.Bfs.Sms.Sdmx.Utils;
namespace Ch.Admin.Bfs.Sms.Sdmx.Extension.CodeBook.Control
{
    public class InternationalStringTypeConverter : TypeConverter
    {
        // Overrides the ConvertTo method of TypeConverter.
        public override object ConvertTo(ITypeDescriptorContext context,
            CultureInfo culture, object value, Type destinationType)
        {
            string info = string.Empty;
            if (destinationType == typeof(string) && value is InternationalizedString)
            {
                InternationalizedString istr = value as InternationalizedString;
                foreach (string key in istr.Keys)
                {
                    if (string.IsNullOrEmpty(istr[key]) == false)
                    {
                        info = key + " - " + istr[key];
                        break;
                    }
                }
                return info;
            }
            return base.ConvertTo(context, culture, value, destinationType);
        }
    }
}
